home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ETO Development Tools 4
/
ETO Development Tools 4.iso
/
Tools - Objects
/
Virtual User 1.0
/
Example Libraries
/
UtilityTasksLib.vu
< prev
Wrap
Text File
|
1991-01-25
|
8KB
|
245 lines
#
# File: UtilityTasksLib.vu
#
# Contains: contains utility tasks for any scripts. Use Mark menu to
# reach the desired task. The tasks are commented on what they do.
#
# Written by: P Nagarajan
#
# Copyright: © 1991 by Apple Computer, Inc., all rights reserved.
#
# Change History:
#
# 1/7/91 naga creation
#
# To Do:
#
(************************************************************************************
* Task GracefulExit( msg )
* Exits VU after printing the supplied 'msg' along with script execution time
************************************************************************************)
Task GracefulExit(msg := '')
begin
println msg;
if( TypeOf( global start_time ) <> 'undefined' )
println "started at : ", global start_time;
println "finished at : ", match[time];
exit;
end; #GracefulExit
(************************************************************************************
* Task UseKeyboardEquivalent( alias )
* Do Menu command using key equivalent
************************************************************************************)
task UseKeyboardEquivalent(alias)
begin
pressKey k: { commandKey };
type k: { alias };
releaseKey k: { commandKey };
end; #UseKeyboardEquivalent
(************************************************************************************
* Task NumberOfWindows()
* Returns the total number of open windows
* In system 7.0's Finder the Desktop is considered a window. This task
* ignores that window and returns the number of regular open windows.
************************************************************************************)
Task NumberOfWindows()
Begin
all_windows := collect[window];
match[application t:?app_name]!;
if not (global System7)
return card all_windows;
else if global System7 and (app_name ~= /≈Finder≈/ )
return card all_windows - 1;
end; #NumberOfWindows
(************************************************************************************
* Task RunningSystemSeven()
* Is the target running System 7.0.x?
************************************************************************************)
Task RunningSystemSeven()
Begin
match [system v:?sys_version];
return (sys_version ~= /7≈/); # 7.0.x system software on target
end; #RunningSystemSeven
(************************************************************************************
* Task OpenOneWindow()
* This task leaves one window open in the Finder
************************************************************************************)
task OpenOneWindow()
begin
success := true;
NumWindows := NumberOfWindows();
if ( NumWindows = 1 ) do
return success;
else if ( NumWindows > 1) do
begin
all_windows := collect[window];
for each w in all_windows do
begin
close[window o:1]!;
end;#for each window
end;
NumWindows := NumberOfWindows();
if ( NumWindows = 0 ) do
begin
if (match [menuItem t:'Open' m:'File' e:true]!) do
begin
select [menuItem t:'Open' m:'File']!;
success := NumberOfWindows();
end; #if a window can be opened thru' the menu
else do
success := false;
end; #no windows currently
else do #could not close all windows
success := false;
return success;
end; #task OpenOneWindow
(************************************************************************************
* Task FindObjectInWindow( at_x, at_y )
* this task moves the mouse on to a particular object of interest. Very useful
* to select files in "view by name" mode in Finder.
* this assumes that the file/icon/object you want to select is on the frontmost
* window with coordinates (at_x, at_y) relative to the window's origin
************************************************************************************)
Task FindObjectInWindow (at_x, at_y)
begin
match [window o:1 r:?rect]!;
icon_x := rect[1] + at_x;
icon_y := rect[2] + at_y;
move a:{icon_x, icon_y};
end; #FindObjectInWindow
(************************************************************************************
* Task LaunchAppInSystem6( appName, launch_wait )
* Check for app running and/or attempt to get there by:
* double-clicking the topmost file (in View by Name) in the frontmost window
* in Finder. ( Intended for use under System 6.0.x )
* launch_wait is the number of seconds to wait before checking for successful
* launch of the application.
************************************************************************************)
Task LaunchAppInSystem6( appName := "", launch_wait := 2 )
Begin
match[application t:?front_App]!;
if not (front_App ~= /≈{appName}≈/)
begin
if (not OpenOneWindow())
begin
println "Could not launch {appName}";
return false;
end;
select [menuItem t:'by Name' m:'View'];
All_Scrollbars := collect [ scrollbar w:1 ];
for each sb in All_Scrollbars
if( sb.r[2] < 32 )
Scroll sb a:{ 0, 1 };
FindObjectInWindow( 9, 46);#first file
DoubleClick;
wait(launch_wait);
match[application t:?front_App]!;
if not (front_App ~= /≈{appName}≈/)
begin
println "Failed to launch {appName}";
return false;
end;
end;
return true;
end; #LaunchAppInSystem6
(************************************************************************************
* Task LaunchAppInSystem7( AppName )
* Check for app running and/or attempt to get there by:
* Using Finder's Find command to select the App, then using the open command.
* ( This works only under System 7.0 )
* launch_wait is the number of seconds to wait before checking for successful
* launch of the application.
************************************************************************************)
Task LaunchAppInSystem7( appName := "", launch_wait := 4 )
Begin
match[application t:?front_App]!;
if not (front_App = appName)
begin
if (not OpenOneWindow())
begin
println "Could not launch {appName}";
return false;
end;
select [ menuitem t:"Find" ];
type k:{ appName, returnKey };
wait(2);
select [ menuitem t:"Open" ];
wait(launch_wait);
match[application t:?front_App]!;
if not (front_App = appName)
begin
Println "Failed to launch ", appName;
return false;
end;
end;
return true;
end; #LaunchAppInSystem7
# *****************************************************************************************
task CheckForAlertWindow(override_alerts := false)
#handles alert dialogs with 'OK' and 'Cancel' buttons.
#if override_alerts is true then select 'OK' else 'Cancel'
begin
if(match[button w:[window ord:1 style:dialog] t:'OK']!) begin
text_messages := collect[staticText w:[window ord:1 style:dialog]]!;
println "dismissing dialog that came up after resource type selection -- static text messages follow:";
for each m in text_messages println " ∂t",m.t;
if override_alerts select [button t:'OK' w:[window ord:1 style:dialog]]!;
else select [button t:'Cancel' w:[window ord:1 style:dialog]]!;
end;#if dialog appeared
end;#CheckForAlertWindow
# *****************************************************************************************
task ThrowItemToTrash(print_any_error := true, override_alerts := false)
# this task trashes a specified object in Finder.
# task assumes that the mouse is already positioned on the item to be trashed
# and that the trash can is positioned on the main screen at (-40,-40) relative to
# the lower right corner.
# Arguements: 'print_any_error' can be used to suppress error messages and
# 'override_alerts' can be used to trash despite alerts.
begin
PressMouse;
match [screen r:?rect m:true]!;
if rect
begin
trash_x := rect[3] - 40; #assumes trash can is at its usual location
trash_y := rect[4] - 40; #ie., (40,40) off form the right bottom corner of main screen
old_mouse_speed := mouseSpeed(5); #slow the mouse down
move a:{trash_x, trash_y};
#move a:{472, 301};#trash can on a SE
mouseSpeed(old_mouse_speed); #reset the mouse speed to what it was before
ReleaseMouse;
CheckForAlertWindow(override_alerts);
if match [menuItem t:'Empty Trash' m:'Special' e:true]!
select [menuItem t:'Empty Trash' m:'Special']!;
else
begin
if print_any_error
println "Empty Trash menu item not enabled, could not trash…";
return false;
end;
end;#if unified correctly
else
begin
if print_any_error
println "Unable to find trash can, could not trash…";
return false;
end;
return true;
end; #ThrowItemToTrash